# -*- coding: utf-8 -*-

class ApplicationAuthController < ApplicationMapController
  before_filter :authcheck
  
  def authcheck
    if (params[:login_name] == "uesaki") and (params[:login_password] == "alohadream_sakemania")
      session[:authorized] = true
      redirect_to params[:next_url]=="///" ? "/admin" : params[:next_url]
      return
    end
    if not session[:authorized]
      if not params[:next_url].nil?
        next_url = params[:next_url]
      elsif not params[:controller].nil?
        next_url = "/"+params[:controller]
        if not params[:action].nil?
          next_url += "/"+params[:action]
          if not params[:id].nil?
            next_url += "/"+params[:id]+"/"
          end
        end
      else
        next_url = "/admin/"
      end

       render :text => <<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>日本酒マニア.com 管理画面</title>
</head>
<body>
  <form action="/admin/index" method="post">
    <input type="hidden" name="next_url" value="#{next_url}" />
    ログイン名<input type="text" name="login_name" /><br />
    パスワード<input type="password" name="login_password" /><br />
    <input type="submit" value="ログイン" />
  </form>
</body>
</html>
END
    end
  end
end
